<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="seatList" stripe border class="tableBox">
      <el-table-column label="序号" type="index" width="80" />
      <el-table-column label="会员等级" prop="level" width="150" align="center" />
      <!-- <el-table-column label="会员价格" prop="price" width="150" align="center" /> -->
      <el-table-column label="会员权益" prop="privilege" class-name="fixed-width" :show-overflow-tooltip="true" />
      <el-table-column label="操作" align="center" width="150">
        <template slot-scope="scope" v-if="scope.row.roleId !== 1">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['basics:seat:edit']">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 编辑席位对话框 -->
    <Z-Dialog :title="title" :visible.sync="open" @confirm="submitForm">
      <el-form ref="form" :model="form" label-width="100px" :rules="rules">
        <el-form-item label="会员等级" prop="level">
          <el-input v-model="form.level" placeholder="请输入会员等级" />
        </el-form-item>
        <!-- <el-form-item label="会员价格" prop="price">
          <el-input v-model="form.price" placeholder="请输入会员价格" />
        </el-form-item> -->
        <el-form-item label="会员权益" prop="privilege">
          <editor :value="form.privilege" :height="500" ref="editor"></editor>
        </el-form-item>
      </el-form>
    </Z-Dialog>

  </div>
</template>

<script>
import { listBaseviplevel, editBaseviplevel } from "@/api/basics/seat.js";

export default {
  name: "seat", //席位
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      seatList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: this.global.pageSize,
        informationName: undefined,

      },
      // 表单参数
      form: {},

      rules: {
        level: [{ required: true, message: "必填", trigger: "blur" }],
        price: [{ required: true, message: "必填", trigger: "blur" }],
        privilege: [{ required: true, message: "必填", trigger: "blur" }],

      }
    };
  },
  created() {
    this.getList();

  },
  methods: {
    getList() {
      this.loading = true;
      listBaseviplevel(this.queryParams)
        .then((response) => {
          if (response.code == 200) {
            this.seatList = response.data;
            this.total = response.total;
          }
          this.loading = false;
        })
        .catch((err) => {
          this.loading = false;
        });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    // 表单重置
    reset() {
      this.resetForm("form");
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.open = true;
      this.form = row;
      this.title = "编辑席位";
    },

    /** 提交按钮 */
    submitForm: function () {
      let valueData = this.$refs.editor.currentValue;
      this.form.privilege = valueData;
      this.$refs.form.validate((valid) => {
        if (valid) {
          if (this.form.id != undefined) {
            editBaseviplevel(this.form).then((response) => {
              this.$modal.msgSuccess("编辑成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
  },
};
</script>
<style lang="scss">
.el-tooltip__popper {
  max-width: 50%;
}

.tableBox {
  th {
    padding: 0 !important;
    height: 48px;
    line-height: 48px;
  }
  td {
    padding: 0 !important;
    height: 48px;
    line-height: 48px;
  }
}
</style>

